package cn.jdy.common.util;

import javax.servlet.http.HttpServletRequest;

/**
 * @desc   解决导出excel中文文件名乱码问题
 * @author ningqian
 * @date   2016-7-27
 *
 */
public class EncodeUtil {
	/**
	 * 解决文件中文名乱码
	 * @param request
	 * @param fileNames
	 * @return
	 */
	 public static String processFileName(HttpServletRequest request, String fileNames) {  
        String codedfilename = null;  
        try {  
            String agent = request.getHeader("USER-AGENT");  
            if (null != agent && -1 != agent.indexOf("MSIE") || null != agent  
                    && -1 != agent.indexOf("Trident")) {// ie  
  
                String name = java.net.URLEncoder.encode(fileNames, "UTF8");  
  
                codedfilename = name;  
            } else if (null != agent && -1 != agent.indexOf("Mozilla")) {// 火狐,chrome等  
  
  
                codedfilename = new String(fileNames.getBytes("UTF-8"), "iso-8859-1");  
            }  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return codedfilename;  
    }  
	
}
